import pickle
import base64
import json


def dumps(dict_data):
    '''
    将字典转换为字符串
    :param dict_data: 字典数据
    :return: 字符串
    '''
    # 将字典转换b'\x**\x**'
    b1 = pickle.dumps(dict_data)
    # 将数据的编码格式转换b'a-zA-Z0-9'
    b2 = base64.b64encode(b1)
    # 转字符串
    b3 = b2.decode()
    # 返回字符串
    return b3


def loads(str_data):
    '''
    将字符串转换为字典
    :param str_data: 字符串
    :return: 字典
    '''
    # 写bytes
    b1 = str_data.encode()
    # 解码
    b2 = base64.b64decode(b1)
    # 转字典
    b3 = pickle.loads(b2)
    # 返回字典
    return b3


if __name__ == '__main__':
    dict1 = {1: 'abc'}
    print(json.dumps(dict1))
    print('-----------')
    print(dumps(dict1))
